<?php
    class DormitoryAllocatingDAL{
        /**
         * action
        * 1-查询所有，查询所有公寓、楼层
        * 2-查询所有，按公寓查询
        * 3-查询所有，按楼层查询
        * 4-查询所有，按公寓、楼层查询
        * 5-分类查询，查询所有公寓、楼层
        * 6-分类查询，查询指定公寓
        * 7-分类查询，查询指定楼层
        * 8-分类查询，查询指定公寓、楼层
        */
        //获取搜索列表（全部）
        public function getSearchApartmentDormitoryList($action,$property,$apartmentID,$floor,$search,$page,$pageSize){
            $result=null;
            //1
            $query_all="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //2
            $query_apartment="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //3
            $query_floor="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //4
            $query_apartment_floor="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //5
            $query_property_all="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //6
            $query_property_apartment="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //7
            $query_property_floor="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id  
            LIMIT :page,:pageSize;";
            //8
            $query_property_apartment_floor="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id 
            order by tb_apartment_info.apartment_id,tb_dormitory_info.floor,tb_dormitory_info.dormitory_id 
            LIMIT :page,:pageSize;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 1:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 2:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 3:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 4:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);//property
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }

            return $result;
        }
        //获取分页
        public function getSearchApartmentDormitoryListPage($action,$property,$apartmentID,$floor,$search){
            $result=null;
            //1
            $query_all="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //2
            $query_apartment="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //3
            $query_floor="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //4
            $query_apartment_floor="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //5
            $query_property_all="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //6
            $query_property_apartment="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //7
            $query_property_floor="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";
            //8
            $query_property_apartment_floor="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_apartment_info.property=:property 
            and tb_dormitory_info.apartment_id=:apartment_id 
            and tb_dormitory_info.floor=:floor 
            and tb_dormitory_info.dormitory_id=:dormitory_id;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 1:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 2:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 3:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 4:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }
            return $result;
        }

        /**
         * 
         * action
         * 1-查询所有，查询所有公寓、楼层
         * 2-查询所有，按公寓查询
         * 3-查询所有，按楼层查询
         * 4-查询所有，按公寓、楼层查询
         * 5-分类查询，查询所有公寓、楼层
         * 6-分类查询，查询指定公寓
         * 7-分类查询，查询指定楼层
         * 8-分类查询，查询指定公寓、楼层
         */
        //获取搜索列表（已分配）
        public function getSearchInstructorDormitoryList($action,$instructorID,$grade,$major,$property,$apartmentID,$floor,$search,$page,$pageSize){
            $result=null;
            //1
            $query_all="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //2
            $query_apartment="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_id=:apartment and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //3
            $query_floor="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and floor=:floor and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //4
            $query_apartment_floor="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_id=:apartment_id and floor=:floor 
            and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //5
            $query_property_all="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //6
            $query_property_apartment="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and apartment_id=:apartment_id 
            and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //7
            $query_property_floor="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and floor=:floor 
            and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //8
            $query_property_apartment_floor="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and apartment_id=:apartment_id and floor=:floor 
            and dormitory_id=:dormitory_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 1:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 2:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 3:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 4:
                    $statement=$pdo->prepare($query_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);//property
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }

            return $result;
        }
        /**
         * 
         * action
         * 1-查询所有，查询所有公寓、楼层
         * 2-查询所有，按公寓查询
         * 3-查询所有，按楼层查询
         * 4-查询所有，按公寓、楼层查询
         * 5-分类查询，查询所有公寓、楼层
         * 6-分类查询，查询指定公寓
         * 7-分类查询，查询指定楼层
         * 8-分类查询，查询指定公寓、楼层
         */
        //获取搜索列表页数（已分配）
        public function getSearchInstructorDormitoryListPage($action,$instructorID,$grade,$major,$property,$apartmentID,$floor,$search){
            $result=null;
            //1
            $query_all="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and dormitory_id=:dormitory_id;";
            //2
            $query_apartment="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_id=:apartment and dormitory_id=:dormitory_id;";
            //3
            $query_floor="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and floor=:floor and dormitory_id=:dormitory_id;";
            //4
            $query_apartment_floor="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_id=:apartment_id and floor=:floor 
            and dormitory_id=:dormitory_id;";
            //5
            $query_property_all="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and dormitory_id=:dormitory_id;";
            //6
            $query_property_apartment="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and apartment_id=:apartment_id 
            and dormitory_id=:dormitory_id;";
            //7
            $query_property_floor="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and floor=:floor 
            and dormitory_id=:dormitory_id;";
            //8
            $query_property_apartment_floor="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_property=:property and apartment_id=:apartment_id and floor=:floor 
            and dormitory_id=:dormitory_id;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 1:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 2:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();break;
                case 3:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 4:
                    $statement=$pdo->prepare($query_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":dormitory_id",$search);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }

            return $result;
        }

        //获取公寓宿舍列表（按公寓和楼层获取）
        public function getApartmentDormitoryList($action,$apartmentID,$floor,$page,$pageSize){
            $result=null;
            $query_apartment="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id 
            order by tb_apartment_info.apartment_id LIMIT :page,:pageSize;";

            $query_floor="select tb_apartment_info.apartment_id,tb_apartment_info.apartment_name,tb_apartment_info.property,tb_dormitory_info.property as dormitory_property,
            tb_dormitory_info.floor,tb_dormitory_info.dormitory_id,tb_dormitory_info.beds,tb_dormitory_info.remarks,tb_dormitory_info.status 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id and tb_dormitory_info.floor=:floor 
            order by tb_apartment_info.apartment_id LIMIT :page,:pageSize;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 0:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 1:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
            }
            return $result;
        }

        //获取公寓宿舍列表（按公寓和楼层获取）
        public function getApartmentDormitoryListPage($action,$apartmentID,$floor,$pageSize){
            $result=null;
            $query_all="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id;";

            $query_floor="select count(1) as count 
            from tb_apartment_info,tb_dormitory_info 
            where tb_apartment_info.apartment_id=tb_dormitory_info.apartment_id 
            and tb_apartment_info.status=1 and tb_dormitory_info.status=1 
            and tb_dormitory_info.apartment_id=:apartment_id and tb_dormitory_info.floor=:floor;";

            $pdo=myPDO::getInstance();
            switch((int)$action){
                case 0:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 1:
                    $statement=$pdo->prepare($query_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    if($statement->execute()){
                        $result=$statement->fetch(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
            }
            return $result;
        }

        //获取辅导员所管理的宿舍
        public function getInstructorDormitoryList($action,$instructorID,$grade,$major,$property,$apartmentID,$floor,$page,$pageSize){
            $result=null;
            /**
             * 获取辅导员所管理的宿舍
             * 1-查询所有。
             * 2-查询所有，按年级查询。
             * 3-查询所有，按专业查询。
             * 4-查询所有，按年级、专业查询
             * 5-查询指定性别。
             * 6-查询所有性别，按年级查询。
             * 7-查询所有性别，按专业查询。
             * 8-查询所有性别，按年级、专业查询。
             * 9-查询所有,按公寓查询
             * 10-查询所有,按公寓、年级查询
             * 11-查询所有,按公寓、专业查询
             * 12-查询所有,按公寓、年级、专业查询
             * 13-查询所有,按公寓、楼层查询
             * 14-查询所有,按公寓、楼层、年级查询
             * 15-查询所有,按公寓、楼层、专业查询
             * 16-查询所有,按公寓、楼层、年级、专业查询
             */
            //1-查询所有
            $query="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //2-查询所有，按年级查询
            $query_grade="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //3-查询所有，按专业查询
            $query_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and major_id=:major_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //4-查询所有，按年级，专业查询
            $query_grade_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //5-查询指定性别。
            $query_property="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //6-查询所有性别，按年级查询。
            $query_property_grade="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and grade=:grade 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //7-查询所有性别，按专业查询。
            $query_property_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and major_id=:major_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //8-查询所有性别，按年级、专业查询。
            $query_property_grade_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and grade=:grade and major_id=:major_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //9-查询所有,按公寓查询
            $query_apartment="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_id=:apartment_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //10-查询所有,按公寓、年级查询
            $query_apartment_grade="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and apartment_id=:apartment_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //11-查询所有,按公寓、专业查询
            $query_apartment_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and major_id=:major_id and apartment_id=:apartment_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //12-查询所有,按公寓、年级、专业查询
            $query_apartment_grade_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and major_id=:major_id and apartment_id=:apartment_id 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";
            //13-查询所有,按公寓、楼层查询
            $query_apartment_floor="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_id=:apartment_id and floor=:floor 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //14-查询所有,按公寓、楼层、年级查询
            $query_apartment_floor_grade="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and apartment_id=:apartment_id and floor=:floor 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //15-查询所有,按公寓、楼层、专业查询
            $query_apartment_floor_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and major_id=:major_id and apartment_id=:apartment_id and floor=:floor 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            //16-查询所有,按公寓、楼层、年级、专业查询
            $query_apartment_floor_grade_major="select uid,apartment_id,apartment_name,floor,dormitory_id,beds,allocated_beds,
            apartment_property,floor_property,dormitory_property 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and major_id=:major_id and apartment_id=:apartment_id and floor=:floor 
            order by apartment_id,floor,dormitory_id LIMIT :page,:pageSize;";

            $pdo=myPDO::getInstance();
            switch($action){
                case 1:
                    $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 2:
                    $statement=$pdo->prepare($query_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 3:
                    $statement=$pdo->prepare($query_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 4:
                    $statement=$pdo->prepare($query_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 9:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 10:
                    $statement=$pdo->prepare($query_apartment_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 11:
                    $statement=$pdo->prepare($query_apartment_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 12:
                    $statement=$pdo->prepare($query_apartment_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 13:
                    $statement=$pdo->prepare($query_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 14:
                    $statement=$pdo->prepare($query_apartment_floor_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 15:
                    $statement=$pdo->prepare($query_apartment_floor_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                case 16:
                    $statement=$pdo->prepare($query_apartment_floor_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    $statement->bindValue(':page',$page,PDO::PARAM_INT);
                    $statement->bindValue(':pageSize',$pageSize,PDO::PARAM_INT);
                    break;
                default:break;
            }
            
            if($statement->execute()){
                $result=$statement->fetchALL(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();
            
            return $result;
        }

        public function getInstructorDormitoryListPage($action,$instructorID,$grade,$major,$property,$apartmentID,$floor){
            //1-查询所有
            $query="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid;";

            //2-查询所有，按年级查询
            $query_grade="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade;";

            //3-查询所有，按专业查询
            $query_major="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and major_id=:major_id;";

            //4-查询所有，按年级，专业查询
            $query_grade_major="select count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and major_id=:major_id;";

            //5-查询指定性别。
            $query_property="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property;";

            //6-查询所有性别，按年级查询。
            $query_property_grade="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and grade=:grade;";

            //7-查询所有性别，按专业查询。
            $query_property_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and major_id=:major_id;";

            //8-查询所有性别，按年级、专业查询。
            $query_property_grade_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_property=:property and grade=:grade and major_id=:major_id;";

            //9-查询所有,按公寓查询
            $query_apartment="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_id=:apartment_id;";

            //10-查询所有,按公寓、年级查询
            $query_apartment_grade=" count(1) as count 
            from view_instructor_dormitory_list 
            where uid=:uid and grade=:grade and apartment_id=:apartment_id;";

            //11-查询所有,按公寓、专业查询
            $query_apartment_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and major_id=:major_id and apartment_id=:apartment_id;";

            //12-查询所有,按公寓、年级、专业查询
            $query_apartment_grade_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and major_id=:major_id and apartment_id=:apartment_id;";

            //13-查询所有,按公寓、楼层查询
            $query_apartment_floor="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and apartment_id=:apartment_id and floor=:floor;";

            //14-查询所有,按公寓、楼层、年级查询
            $query_apartment_floor_grade="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and apartment_id=:apartment_id and floor=:floor;";

            //15-查询所有,按公寓、楼层、专业查询
            $query_apartment_floor_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and major_id=:major_id 
            and apartment_id=:apartment_id and floor=:floor;";

            //16-查询所有,按公寓、楼层、年级、专业查询
            $query_apartment_floor_grade_major="select count(1) as count 
            from view_instructor_dormitory_list  
            where uid=:uid and grade=:grade and major_id=:major_id 
            and apartment_id=:apartment_id and floor=:floor;";

            $pdo=myPDO::getInstance();
            switch($action){
                case 1:
                    $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    break;
                case 2:
                    $statement=$pdo->prepare($query_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    break;
                case 3:
                    $statement=$pdo->prepare($query_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 4:
                    $statement=$pdo->prepare($query_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 5:
                    $statement=$pdo->prepare($query_property,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    break;
                case 6:
                    $statement=$pdo->prepare($query_property_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":grade",$grade);
                    break;
                case 7:
                    $statement=$pdo->prepare($query_property_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 8:
                    $statement=$pdo->prepare($query_property_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":property",$property);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 9:
                    $statement=$pdo->prepare($query_apartment,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    break;
                case 10:
                    $statement=$pdo->prepare($query_apartment_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":grade",$grade);
                    break;
                case 11:
                    $statement=$pdo->prepare($query_apartment_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 12:
                    $statement=$pdo->prepare($query_apartment_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    break;
                case 13:
                    $statement=$pdo->prepare($query_apartment_floor,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    break;
                case 14:
                    $statement=$pdo->prepare($query_apartment_floor_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    break;
                case 15:
                    $statement=$pdo->prepare($query_apartment_floor_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    break;
                case 16:
                    $statement=$pdo->prepare($query_apartment_floor_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructorID);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":apartment_id",$apartmentID);
                    $statement->bindValue(":floor",$floor);
                    break;
                default:break;
            }
            
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();
            
            return $result;
        }

        //获取已使用的床位数量
        public function getBedsAlreadyUsedQuantity($apartmentID,$floor,$dormitoryID,$grade,$major){
            $query="select sum(beds) as count from tb_instructor_dormitory_allocating_list 
            where apartment_id=:apartment_id and floor=:floor and dormitory_id=:dormitory_id 
            and status=1";
            
            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(":apartment_id",$apartmentID);
            $statement->bindValue(":floor",$floor);
            $statement->bindValue(":dormitory_id",$dormitoryID);
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();

            return $result;
        }

        //获取辅导员在该宿舍已分配的床位数量
        public function getInstructorBedsAlreadyUsedQuantity($apartmentID,$floor,$dormitoryID,$uid,$grade,$major){
            $query="select beds from tb_instructor_dormitory_allocating_list 
            where apartment_id=:apartment_id and floor=:floor 
            and dormitory_id=:dormitory_id and 
            uid=:uid and grade=:grade and major_id=:major_id 
            and status=1";
            
            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(":apartment_id",$apartmentID);
            $statement->bindValue(":floor",$floor);
            $statement->bindValue(":dormitory_id",$dormitoryID);
            $statement->bindValue(":uid",$uid);
            $statement->bindValue(":grade",$grade);
            $statement->bindValue(":major_id",$major);
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();

            return $result;
        }

        //分配宿舍
        public function instructorAllocatingDormitories($dormitoryList){
            $flag=false;
            $query="insert into tb_instructor_dormitory_allocating_list(uid,grade,major_id,apartment_id,floor,dormitory_id,beds,add_time,status) 
            values(:uid,:grade,:major_id,:apartment_id,:floor,:dormitory_id,:beds,now(),1);";

            $query_update="update tb_instructor_dormitory_allocating_list set beds=:beds 
            where uid=:uid and grade=:grade and major_id=:major_id and apartment_id=:apartment_id 
            and floor=:floor and dormitory_id=:dormitory_id and status=1;";

            $pdo=myPDO::getInstance();
            
            foreach($dormitoryList as $dormitory){
                switch((int)$dormitory->action){
                    case 1:
                        $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                        $statement->bindValue(":uid",$dormitory->instructorID);
                        $statement->bindValue(":grade",$dormitory->grade);
                        $statement->bindValue(":major_id",$dormitory->major);
                        $statement->bindValue(":apartment_id",$dormitory->apartmentID);
                        $statement->bindValue(":floor",$dormitory->floor);
                        $statement->bindValue(":dormitory_id",$dormitory->dormitoryID);
                        $statement->bindValue(":beds",$dormitory->beds);
                        $flag=$statement->execute();
                        break;
                    case 2:
                        $statement=$pdo->prepare($query_update,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                        $statement->bindValue(":uid",$dormitory->instructorID);
                        $statement->bindValue(":grade",$dormitory->grade);
                        $statement->bindValue(":major_id",$dormitory->major);
                        $statement->bindValue(":apartment_id",$dormitory->apartmentID);
                        $statement->bindValue(":floor",$dormitory->floor);
                        $statement->bindValue(":dormitory_id",$dormitory->dormitoryID);
                        $statement->bindValue(":beds",$dormitory->beds);
                        $flag=$statement->execute();
                        break;
                    default:break;
                }
            }
            $statement->closeCursor();

            return $flag;
        }

        //移除分配的宿舍
        public function instructorAllocatingDormitoriesRemove($dormitoryList){
            $flag=false;
            $query="update tb_instructor_dormitory_allocating_list set status=0
            where uid=:uid and grade=:grade and major_id=:major_id and apartment_id=:apartment_id 
            and floor=:floor and dormitory_id=:dormitory_id and status=1;";

            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            foreach($dormitoryList as $dormitory){
                $statement->bindValue(":uid",$dormitory->instructorID);
                $statement->bindValue(":grade",$dormitory->grade);
                $statement->bindValue(":major_id",$dormitory->major);
                $statement->bindValue(":apartment_id",$dormitory->apartmentID);
                $statement->bindValue(":floor",$dormitory->floor);
                $statement->bindValue(":dormitory_id",$dormitory->dormitoryID);
                $flag=$statement->execute();
            }
            $statement->closeCursor();
            
            return $flag;
        }

        //是否已分配该宿舍，按公寓、楼层、宿舍、辅导员、年级、专业查找
        public function isAllocatingDormitory($apartmentID,$floor,$dormitoryID,$uid,$grade,$major){

            $query="select count(1) as count from tb_instructor_dormitory_allocating_list 
            where apartment_id=:apartment_id and floor=:floor and dormitory_id=:dormitory_id 
            and uid=:uid and grade=:grade and major_id=:major_id and status=1;";

            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(":apartment_id",$apartmentID);
            $statement->bindValue(":floor",$floor);
            $statement->bindValue(":dormitory_id",$dormitoryID);
            $statement->bindValue(":uid",$uid);
            $statement->bindValue(":grade",$grade);
            $statement->bindValue(":major_id",$major);
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();

            return $result;
        }
    }
?>